/*
 * @Author: linxun 
 * @Date: 2021-03-09 10:07:45 
 * @Last Modified by: linxun
 * @Last Modified time: 2021-07-23 15:38:04
 * @Description: 添加图片
 */

import React, { useState, useRef, Fragment } from 'react';
import { Modal, Form, Radio, Button } from 'antd';
import { useIntl } from 'umi';
import { FORMLAYOUT_1 } from '@/utils/const';
import SecondStep from './SecondStep';

const FormItem = Form.Item;
const RadioGroup = Radio.Group;

const AddImage = props => {
  const { formatMessage } = useIntl();
  const rowDataRef = useRef();
  const { visible, loading, cancel, onOk, ...others } = props;
  const [submitDisabled, setSubmitDisabled] = useState(false);
  const addImageRef = useRef();

  const onSubmit = () => {
    const { rowDataRef, secondForm } = addImageRef.current;
    secondForm.validateFields().then(values => {
      onOk(values, rowDataRef);
    }).catch(err => {
      console.log(err);
    });
  };

  return (
    <Modal
      title='添加图片'
      visible={visible}
      confirmLoading={loading}
      onCancel={cancel}
      maskClosable={false}
      width='80%'
      style={{ maxWidth: 1200 }}
      footer={(
        <Fragment>
          <Button onClick={cancel}>取消</Button>
          <Button type='primary' onClick={onSubmit} disabled={submitDisabled}>确定</Button>
        </Fragment>
      )}
      destroyOnClose
    >
      <SecondStep setDisabled={setSubmitDisabled} ref={addImageRef} {...others} />
    </Modal>
  )
}

export default AddImage;